﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
using Business;
using System.Globalization;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class ThemNhanVien : System.Web.UI.Page
    {
        Business.QuanLyNhanVien qlnhanvien = new Business.QuanLyNhanVien();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loaddulieu();
            }
        }
        public void loaddulieu()
        {
            ddlNguoiQuanLy.DataSource = qlnhanvien.LayDanhSachNhanVien();           
            ddlNguoiQuanLy.DataTextField = "HoTenNV";
            ddlNguoiQuanLy.DataValueField = "MaNV";
            ddlNguoiQuanLy.DataBind();
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Response.Redirect("QuanLyNhanVien.aspx");
        }
        private void reset()
        {
            txtCMNDNV.Text = "";
            txtMaNV.Text = "";
            txtHoTenNV.Text = "";
            txtDiaChiNV.Text = "";
            txtDienThoaiNV.Text = "";
            txtCMNDNV.Text = "";
            txtEmailNV.Text = "";
            txtLương.Text = "";
        }
        protected void btnThemNV_Click(object sender, EventArgs e)
        {
            NhanVien nhanvien = new NhanVien
            {
                MaNV = txtMaNV.Text,
                HoTenNV = txtHoTenNV.Text,
                 NgaySinh = System.DateTime.ParseExact(Request["txtNgaysinh"], "MM/dd/yyyy", CultureInfo.InvariantCulture),
                DiaChi = txtDiaChiNV.Text,
                GioiTinh = ddlGioiTinhHV.SelectedValue,
                ChucVu=ddlChucVu.SelectedValue,
                Luong=float.Parse(txtLương.Text),            
                DienThoai = txtDienThoaiNV.Text,
                CMND = txtCMNDNV.Text,
                Email = txtEmailNV.Text,
                
            };
            if (qlnhanvien.ThemNhanVien(nhanvien))
            {
               
                Response.Write("<script language='javascript' type='text/javascript'>"
                           + " alert('Thêm nhân viên thành công');"
                           + "</script>");
              
                reset();
            }
            else
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                              + " alert('Không thể thêm nhân viên này');"
                              + "</script>");
             
            }
        }
    }
}